#pragma once
#include "Channel.h"
#include "Noncopyable.h"
#include "Socket.h"
#include <functional>

class EventLoop;
class InetAddress;

class Acceptor : Noncopyable
{
  public:
    using NewConnectionCallback =
        std::function<void(int sockfd, const InetAddress &)>;

  private:
    EventLoop *loop_; // Acceptor用的就是用户定义的loop也就是mainLoop
    Socket acceptSocket_;
    Channel acceptChannel_;
    NewConnectionCallback newConnectionCallback_;
    bool listenning_;

  public:
    Acceptor(EventLoop *loop, const InetAddress &listenAddr, bool reuseport);
    ~Acceptor();
    void setNewConnectionCallback(const NewConnectionCallback &cb)
    {
        newConnectionCallback_ = cb;
    }
    bool listenning() const
    {
        return listenning_;
    }
    void listen();

  private:
    void handleRead();

}; // class Acceptor
